package com.edu.chat.web.controller;

import com.edu.chat.web.common.model.R;
import com.edu.chat.web.controller.vo.LibraryVO;
import com.edu.chat.web.controller.vo.PageQuery;
import com.edu.chat.web.dto.LibraryInfoDTO;
import com.edu.chat.web.dto.PageResult;
import com.edu.chat.web.service.CsLibraryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @program: KQAIA
 * @description: 知识库管理
 * @author: 无恙
 * @create: 2025-03-19 12:34
 **/

@RestController
@RequestMapping("/chat/library")
@Slf4j
public class LibraryController {

	@Autowired
	private CsLibraryService csLibraryService;

	//新建知识库
	@PostMapping("/create")
	public R<Boolean> createLibrary(@RequestBody @Validated LibraryVO libraryVO) {
		log.info("创建知识库，参数：{}", libraryVO);
		return csLibraryService.createLibrary(libraryVO);
	}

	//分页查询知识库
	@PostMapping("/list")
	public R<?> listLibrary(@RequestBody @Validated PageQuery<LibraryVO> pageQuery) {
		PageResult<LibraryInfoDTO> libraryInfoDTOPageResult = csLibraryService.listLibrary(pageQuery);
		return R.success(libraryInfoDTOPageResult);
	}

	//更改知识库开关
	@GetMapping("/update/enable/{id}")
	public R<Boolean> updateEnable(@PathVariable("id") String id) {
		return csLibraryService.updateLibraryEnable(id);
	}

	//编辑知识库
	@PostMapping("/update")
	public R<Boolean> updateLibrary(@RequestBody @Validated LibraryVO libraryVO) {
		return csLibraryService.updateLibrary(libraryVO);
	}

	//删除知识库
	@GetMapping("/delete/{id}")
	public R<Boolean> deleteLibrary(@PathVariable("id") String id) {
		return csLibraryService.deleteLibrary(id);
	}



}
